<template>
	<view class="content">
		<!-- 导航栏 -->
		<view class="head">
			<!-- 状态栏高度 -->
			<view :style="{ height: `${statusBarHeight}px` }"></view>
			<!-- <text class="text">创意岛资源圈</text> -->
			<!-- 自定义导航栏高度 并 居中 -->
			<view :style="{
			          height: `${barHeight}px`,
			          'line-height': `${barHeight}px`,
			          'text-align': 'center',
			        }">
				<h5>荔枝教育</h5>
			</view>
		</view>
		<view class="logo" style="text-align: center; margin-top: 130rpx;">
			<image style="width: 436rpx; height: 450rpx;"
				src="https://xiyanluo.oss-cn-beijing.aliyuncs.com/%E8%8D%94%E8%87%B4%E5%AE%B6%E6%95%99/logo.png"
				mode="">
			</image>
		</view>
		<view class="text">
			<p>您还没有绑定手机号，</p>
			<p>无法享受我们专属定制的服务，点击按钮绑定</p>
		</view>
		<view class="login">
			<button  @click="getUserInfo"
				style="display: flex;align-items: center; justify-content: center;">
				<!-- 				<image style="width: 48rpx; height: 37rpx; margin-right: 15rpx;" src="../../static/image/wx.png"
					mode=""></image> -->
				手机号快捷登录
			</button>
		</view>
	</view>
</template>

<script>
	import homeIndexVue from '../home/homeIndex.vue';
	export default {
		data() {
			return {
				hightNum: 0,
				statusBarHeight: '',
				barHeight: ''
			}
		},
		onLoad() {
			// uni.login({
			// 	success: async (res) => {
			// 		console.log('1aaaaaaaaaaa', res);
					
			// 		uni.request({
			// 			url: 'https://app.lzjiajiaoshe.com/litchi/api/Account/wxLogin',
			// 			data: {
			// 				appType: 0,
			// 				code: res.code,
			// 				inviteId: this.inviteId ? this.inviteId : ''
			// 			},
			// 			method: "get",
			// 			header: {
			// 				'content-type': 'application/x-www-form-urlencoded',
			// 			},
			// 			success: (result) => {
			// 				this.$u.vuex('vuex_hasLogin', true)
			// 				console.log('112222222221', result);
			// 				this.$u.vuex('vuex_token', result.data.data.token)
			// 				uni.setStorageSync('code', result.data.msg)
			// 				uni.setStorageSync('Headtoken', result.data.data.token)
			// 				uni.setStorageSync('sessionKey', result.data.data.sessionKey)
			// 			}
			// 		})
			// 		// const result = await this.$u.api.miniWxLogin({
			// 		// 	appType: 0,
			// 		// 	code: res.code,
			// 		// 	inviteId: this.inviteId ? this.inviteId : ''
			// 		// })
			// 		// this.$u.vuex('vuex_hasLogin', true)
			// 		// console.log('112222222221', result);
			// 		// this.$u.vuex('vuex_token', result.token)
			// 		// uni.setStorageSync('code', result.code)
			// 		// uni.setStorageSync('Headtoken', result.token)
			// 		// uni.setStorageSync('sessionKey', result.sessionKey)

			// 	}
			// })
			// 状态栏高度
			this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			// 胶囊数据
			const {
				top,
				height
			} = wx.getMenuButtonBoundingClientRect();
			// 自定义导航栏高度 = 胶囊高度 + 胶囊的padding*2, 如果获取不到设置为38
			this.barHeight = height ? height + (top - this.statusBarHeight) * 2 : 38;
		},
		onReady() {},
		methods: {
			getUserInfo() {
				uni.login({
					success: async (res) => {
						console.log('1aaaaaaaaaaa', res);
						const result = await this.$u.api.miniWxLogin({
							appType: 0,
							code: res.code,
							inviteId: this.inviteId ? this.inviteId : ''
						})
						console.log('112222222221', result.code);
						this.$u.vuex('vuex_token', result.token)
						this.$u.vuex('vuex_user', result.user)
						this.$u.vuex('vuex_hasLogin', true)
						this.$u.toast('登陆成功');
						setTimeout(() => {
							if(result.isOld==1){
								uni.switchTab({
									url: '/pages/home/homeIndex'
								})
							}
							else{
								uni.navigateTo({
									url:'/pages/my/personal'
								})
							}
						}, 2000)
					}
				})
			
			},
			async getPhoneNumber(e) {
				console.log(e);
				let that = this
				if (uni.getStorageSync('code') == '需要绑定手机') {
					const res = await that.$u.api.getPhone({
						encryptedData: e.target.encryptedData,
						iv: e.target.iv,
						sessionKey: uni.getStorageSync('sessionKey'),
					})

					uni.showToast({
						title: '绑定成功'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/home/homeIndex'
						})
					}, 500)


				} else {
					uni.showToast({
						title: '绑定成功'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/home/homeIndex'
						})
					}, 500)
				}

			},
			getPhone() {

			},
			checkCode() {
				let that = this;
				wx.checkSession({
					success() {
						//session_key 未过期，并且在本生命周期一直有效
						uni.login({
							success: res => {
								that.$u.vuex('vuex_wxcode', res.code);
							},
							fail(err) {
								that.$u.toast('获取code失败');
							}
						});
					},
					fail() {
						// session_key 已经失效，需要重新执行登录流程
						uni.login({
							success: res => {
								that.$u.vuex('vuex_wxcode', res.code);
							},
							fail(err) {
								that.$u.toast('获取code失败');
							}
						});
					}
				});
			},
			cancel() {
				uni.switchTab({
					url: '/pages/my/myIndex'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {


		.head {
			width: 100%;
			background: #fff;

			h5 {
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #000000;
			}
		}

		.text {
			margin-top: 69rpx;
			padding: 0 76rpx;
			text-align: center;

			p {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 53rpx;
			}
		}

		.login {
			margin-top: 92rpx;
			padding: 0 60rpx;

			button {

				width: 631rpx;
				height: 88rpx;
				background: linear-gradient(90deg, #FF8D5F, #FF6A55);
				border-radius: 44rpx;
				font-size: 30rpx;
				color: #F8F8F9;
			}
		}
	}
</style>